<?php
/**
 *
 *
 * 功能说明：系统管理。
 *
 **/

namespace Qwadmin\Controller;

class NumberController extends ComController
{
    public function cai()
    {
        if (IS_POST) {
            // dump(I());
            // exit;
            $norm  = $_POST['name'];
            $norm2  = $_POST['name2'];
            // $yue = date('m');
            $ri = date('d');
            if ($ri > '10') {
                $yue = date('m');
            }else{
                $yue = date('m',strtotime("-1 month"));
            }
            // echo $yue;
            // exit;
            // echo $norm . $norm2;
            // exit;
            $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->find();

            // P($ulist);
            $uname = $ulist['user'];
            // echo $uname;
            // exit;
            //判断当前用户是否是评分人;
            $pr = M('ping')->where(['norm'=>['in',array($norm,$norm2)],'yue'=>$yue,'pname'=>$uname,'g_type'=>'1'])->select();
            if (empty($pr)) {
                echo '您不是评分人';
                exit;
            }else{
                foreach ($pr as  $value) {
                    if (!empty($value['score'])) {
                        $this->ajaxReturn('请不要重复评分');
                    }
                }
            }
            $list['result'] = $_POST['result'];
            $list2['result'] = $_POST['result2'];
            // 到诊完成率分数添加
            if (M('ping')->where(['norm'=>$norm,'pname'=>$uname,'g_type'=>'1','yue'=>$yue])->save($list) > 0) {
                //成本控制率添加
                if (M('ping')->where(['norm'=>$norm2,'pname'=>$uname,'g_type'=>'1','yue'=>$yue])->save($list2) > 0) {
                    
                    //查询到诊完成率评分总人数----------------------------------------------------------------------------------------
                        $plist = M('ping')->where(['norm'=>$norm,'yue'=>$yue,'g_type'=>'1'])->distinct(true)->field('pname')->select();
                        // P($plist);
                        //查询到诊完成率已评分人数
                        $plist2 = M('ping')->where(['norm'=>$norm,'yue'=>$yue,'result'=>['neq','null'],'g_type'=>'1'])->distinct(true)->field('pname')->select();
                        
                        //↓ 获取考核信息的id
                        $pidlist = M('plan')->where(['norm'=>$norm,'yue'=>$yue,'g_type'=>'1'])->distinct(true)->field('id')->select();
                        foreach ($pidlist as  $va) {
                            $pid .= "`pid`="."'".$va['id']."'"." or ";
                        }
                        $pid = rtrim($pid,'or ');
                        //↑ 获取考核信息的id END 
                        
                        $num = count($plist);
                        $num2 = count($plist2);
                        // echo $num .'-'. $num2;
                        // exit;
                        //判断到诊完成率评分人是否都评完;
                        if ($num == $num2) {
                            //计算到诊完成率衡量结果核算结果的平均数;
                            $result = M('ping')->where(['norm'=>$norm,'yue'=>$yue,'result'=>['neq','null'],'g_type'=>'1'])->distinct(true)->field('result,pname,weight')->select();
                            // P($result);
                            // dump($result);
                            // exit;
                            // //计算到诊完成率标准分的平均数;
                            // $standard = M('ping')->where(['norm'=>$norm,'yue'=>$yue,'standard'=>['neq','null']])->distinct(true)->field('standard,pname')->select();

                            // //计算到诊完成率考核得分的平均数;
                            // $score = M('ping')->where(['norm'=>$norm,'yue'=>$yue,'score'=>['neq','null']])->distinct(true)->field('score,pname')->select();
                             // P($score);
                            $rnum = 0;
                            foreach ($result as  $v) {
                                $rnum = $v['result'];
                            }  
                            // echo $rnum;
                            // echo $num;
                            // exit;
                            // $snum = 0;
                            // foreach ($standard as  $v) {
                            //     $snum += $v['standard'];
                            // } 
                           
                            // $ssnum = 0;
                            // foreach ($score as  $v) {
                            //     $ssnum += $v['score'];
                            // } 
                            // echo $rnum . '/'.$snum .'/'. $ssnum;
                            // echo '<br>';
                            // dump($result);A7329522aas.
                            // dump($standard);
                            // dump($score);
                            // echo '<hr>';
                            //获得到诊完成率衡量结果核算结果的平均分;
                            $ping['result'] = $rnum / $num;
                            if ($ping['result'] < '100' && $ping['result'] >= '80') {
                               $cha = 100 - $ping['result'];
                               // echo $cha;
                               $que = $cha * 5;
                               $ping['standard'] = 100 - $que;
                               // echo $value=90*0.1;
                               // echo $ping['standard'];
                            }else if($ping['result'] >= '100'){
                                        $ping['standard'] = '100';
                            }else if($ping['result'] <= '80'){
                                        $ping['standard'] = '0';
                            }
                            // dump($ping);
                            // exit;
                            $weight = $result[0]['weight'].'%';
                            $ping['score'] = $ping['standard'] / $weight;
                            // exit;
                            // if ($ping['result'] >= '100') {
                            //     $ping['standard'] = '100';
                            // }else if($ping['result'] < '80'){
                            //     $ping['standard'] = '0';
                            // }
                            // dump($ping);
                            // exit;
                            //获得到诊完成率标准分的平均分;
                            // $ping['standard'] = $snum / $num;
                            // //获得到诊完成率考核得分的平均分;
                            // $ping['score'] = $ssnum / $num;
                            // P($ping);
                            //讲到诊完成率平均分添加到plan表里
                            if (M('plan')->where(['norm'=>$norm,'yue'=>$yue,'g_type'=>'1'])->save($ping) > 0) {
                                //讲到诊完成率平均分添加到people表里
                                M('people')->where($pid)->save($ping);
                            }
                        }

                    //以上完成到诊完成率的平均分总和 ---------------------------------------------------------------------------------------------



                    //查询成本控制率评分总人数----------------------------------------------------------------------------------------
                        $clist = M('ping')->where(['norm'=>$norm2,'yue'=>$yue,'g_type'=>'1'])->distinct(true)->field('pname')->select();
                        // dump($plist);
                        // exit;
                        //查询成本控制率已评分人数
                        $clist2 = M('ping')->where(['norm'=>$norm2,'yue'=>$yue,'result'=>['neq','null'],'g_type'=>'1'])->distinct(true)->field('pname')->select();
                        // P($plist2);
                         //↓ 获取考核信息的id
                        $cidlist = M('plan')->where(['norm'=>$norm2,'yue'=>$yue,'g_type'=>'1'])->distinct(true)->field('id')->select();
                        foreach ($cidlist as  $va) {
                            $cid .= "`pid`="."'".$va['id']."'"." or ";
                        }
                        $cid = rtrim($cid,'or ');
                        // echo $cid;
                        // exit;
                        //↑ 获取考核信息的id END 
                        $cnum = count($clist);
                        $cnum2 = count($clist2);
                        // echo $cnum . $cnum2;
                        // exit;
                        //判断成本控制率评分人是否都评完;
                        if ($cnum == $cnum2) {
                           $dresult = M('ping')->where(['norm'=>$norm2,'yue'=>$yue,'result'=>['neq','null'],'g_type'=>'1'])->distinct(true)->field('result,pname,weight')->select();

                            // //计算到诊完成率标准分的平均数;
                            // $dstandard = M('ping')->where(['norm'=>$norm2,'yue'=>$yue,'standard'=>['neq','null']])->distinct(true)->field('standard,pname')->select();

                            // //计算到诊完成率考核得分的平均数;
                            // $dscore = M('ping')->where(['norm'=>$norm2,'yue'=>$yue,'score'=>['neq','null']])->distinct(true)->field('score,pname')->select();
                             // P($score);
                            $drnum = 0;
                            foreach ($dresult as  $v) {
                                $drnum = $v['result'];
                            }  

                            // $dsnum = 0;
                            // foreach ($dstandard as  $v) {
                            //     $dsnum += $v['standard'];
                            // } 
                           
                            // $dssnum = 0;
                            // foreach ($dscore as  $v) {
                            //     $dssnum += $v['score'];
                            // } 
                            //获得到诊完成率衡量结果核算结果的平均分;
                            $dping['result'] = $drnum / $cnum;
                            if ($dping['result'] > '100' && $dping['result'] <= '120') {
                               $cha = 120 - $dping['result'];
                               // echo $cha;
                               // exit;
                               $que = $cha * 5;
                               $dping['standard'] = 100 - $que;
                               // echo $value=90*0.1;
                               // echo $dping['standard'];
                            }else if($dping['result'] <= '100'){
                                        $dping['standard'] = '100';
                            }else if($dping['result'] >= '120'){
                                        $dping['standard'] = '0';
                            }
                            // dump($dping);
                            // exit;
                            $weight = $result[0]['weight'].'%';
                            $dping['score'] = $dping['standard'] / $weight;
                            //获得到诊完成率标准分的平均分;
                            // $dping['standard'] = $dsnum / $cnum;
                            // //获得到诊完成率考核得分的平均分;
                            // $dping['score'] = $dssnum / $cnum;
                        
                            // dump($dping);
                            // exit;  

                            //讲成本控制率平均分添加到plan表里
                            if (M('plan')->where(['norm'=>$norm2,'yue'=>$yue,'g_type'=>'1'])->save($dping) > 0) {
                                //讲成本控制率平均分添加到people表里
                                M('people')->where($cid)->save($dping);
                            }
                        }

                    //以上完成成本控制率的平均分总和 ---------------------------------------------------------------------------------------------
                        echo '1111';
                    
                }
                
            }else{
                echo '2222';
            }
        }else{
            // $yue = date('m');
            $ri = date('d');
            if ($ri > '10') {
                $yue = date('m');
            }else{
                $yue = date('m',strtotime("-1 month"));
            }
            $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->find();

            if ($ulist['ment'] == '集团绩效管理委员会') {
                $list = M('ping')->where(['m_type'=>['in',array(1,3)],'g_type'=>'1','i'=>'1'])->order('k_time desc')->select();
                $j_yue  = M('ping')->where(['m_type'=>['in',array(1,3)],'g_type'=>'1','i'=>'1'])->distinct(true)->field('k_time')->order('k_time desc')->select();
                // dump($list);
                // exit;
                $this->assign('list',$list);
                $this->assign('j_yue',$j_yue);
                $this->display('cailist');
                // exit;
            }else{
                $this->assign('yue',$yue);
                $this->display();
            }
            // $this->assign('time',$time);
            // $this->assign('empty',$empty);
            
        }
    	
    }





    //网络中心财务指标
    public function wcai()
    {
        if (IS_POST) {
            // 查詢當前登入用戶信息
            $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->find();
            $uname = $ulist['user'];
            $list['result'] = $_POST['result'];
            // $list['standard'] = $_POST['standard'];
            // $list['score'] = $_POST['score'];
            if (empty($_POST['result'])) {
                echo '分数为空';
                exit;
            }
            // P($pzong);
            // dump($_POST);
            // dump($list);
            // exit;
            // P($res);
            if (M('ping')->where(['pid'=>$_POST['id'],'yue'=>$_POST['yue'],'pname'=>$uname,'uname'=>$_POST['uname']])->save($list) > 0) {
                    //評分總人數
                    $pzong = M('ping')->where(['pid'=>$_POST['id'],'uname'=>$_POST['uname']])->distinct(true)->field('pname')->count();
                    // echo $pzong;
                    // exit;
                    //已評人數
                    $px = M('ping')->where(['pid'=>$_POST['id'],'uname'=>$_POST['uname'],'result'=>['neq','null']])->distinct(true)->field('pname')->count();
                    if ($px == $pzong) {
                        // echo '12';
                        // exit;
                        $zong = M('ping')->where(['pid'=>$_POST['id'],'uname'=>$_POST['uname'],'yue'=>$_POST['yue'],'result'=>['neq','null']])->distinct(true)->field('result,pname,norm,weight')->select();
                        // P($result);
                        // dump($zong);
                        // exit;
                        
                        $rnum = 0;
                        foreach ($zong as $key => $v) {
                            $rnum += $v['result'];
                           
                        }
                        // echo $rnum;
                        // exit;
                        //获得到衡量结果核算结果的平均分;
                        $ping['result'] = $rnum / $pzong;
                        switch ($zong[0]['norm']) {
                            case '到诊完成率':
                                if ($ping['result'] < '100' && $ping['result'] >= '80') {
                                   $cha = 100 - $ping['result'];
                                   // echo $cha;
                                   $que = $cha * 5;
                                   $ping['standard'] = 100 - $que;
                                   // echo $value=90*0.1;
                                   // echo $ping['standard'];
                                }else if($ping['result'] >= '100'){
                                            $ping['standard'] = '100';
                                }else if($ping['result'] <= '80'){
                                            $ping['standard'] = '0';
                                }                                
                                break;
                            case '成本控制率':
                                if ($ping['result'] > '100' && $ping['result'] <= '120') {
                                   $cha = 120 - $ping['result'];
                                   
                                   $que = $cha * 5;
                                   $ping['standard'] = 100 - $que;
                              
                                }else if($ping['result'] <= '100'){
                                            $ping['standard'] = '100';
                                }else if($ping['result'] >= '120'){
                                            $ping['standard'] = '0';
                                }
                                break;
                            case '转化完成率':
                                if ($ping['result'] > '80' && $ping['result'] < '100') {
                                   $cha = 100 - $ping['result'];
                                   
                                   $que = $cha * 5;
                                   $ping['standard'] = 100 - $que;
                              
                                }else if($ping['result'] >= '100'){
                                            $ping['standard'] = '100';
                                }else if($ping['result'] <= '80'){
                                            $ping['standard'] = '0';
                                }
                                break;
                            case '对话量完成率':
                                if ($ping['result'] > '80' && $ping['result'] < '100') {
                                   $cha = 100 - $ping['result'];
                                   
                                   $que = $cha * 5;
                                   $ping['standard'] = 100 - $que;
                              
                                }else if($ping['result'] >= '100'){
                                            $ping['standard'] = '100';
                                }else if($ping['result'] <= '80'){
                                            $ping['standard'] = '0';
                                }
                                break;
                            case '对话转化率':
                                if ($ping['result'] > '85' && $ping['result'] < '95') {
                                   $cha = 100 - $ping['result'];
                                   
                                   $que = $cha * 10;
                                   $ping['standard'] = 100 - $que;
                              
                                }else if($ping['result'] >= '95'){
                                            $ping['standard'] = '100';
                                }else if($ping['result'] <= '85'){
                                            $ping['standard'] = '0';
                                }
                                break;
                        }

                        // dump($ping);
                        // exit;

                        $weight = $zong[0]['weight'].'%';
                        $ping['score'] = $ping['standard'] / $weight;
                        
                        M('people')->where(['pid'=>$_POST['id'],'uname'=>$_POST['uname'],'yue'=>$_POST['yue']])->save($ping);
                        M('ping')->where(['pid'=>$_POST['id'],'uname'=>$_POST['uname'],'yue'=>$_POST['yue']])->save($ping);
                        M('plan')->where(['id'=>$_POST['id'],'yue'=>$_POST['yue']])->save($ping);

                    }
                    


                echo $ping['result'];
            }else{
                echo '2222';
            }
        }else{
            //查询当前用户信息
            $uid = $_SESSION['uid'];
            $ulist = M('member')->where(['uid'=>$uid])->find();
            $uname = $ulist['user'];
            $yue = date('m');
            $ri = date('d');
            // echo $ri;
            // exit;
            if ($ri >= 10) {
                $dtime = date('Y-m').'-'.'11';
            }else{
                $dtime = date('Y-m').'-'.'10';
            }

            if ($ulist['ment'] == '集团绩效管理委员会') {
                //查询当前用户所要评分考核信息表;
                $ylist = M('ping')->where(['m_type'=>['in',array(1,3)],'g_type'=>'2','i'=>'1'])->distinct(true)->field('pid,uname,yue,target,norm,weight,value,rule,num,ment,result,standard,score,score,k_time,e_time')->order('uname desc')->select();
                $j_yue  = M('ping')->where(['m_type'=>['in',array(1,3)],'g_type'=>'2','i'=>'1'])->distinct(true)->field('k_time')->order('k_time desc')->select();
                // dump($list);
                // exit;
                $this->assign('ylist',$ylist);
                $this->assign('j_yue',$j_yue);
                $this->display('wcailist');
                // exit;
            }else{
                $map['e_time'] = $dtime;
                $map['yue'] = $yue;
                $map['_logic'] = 'or';
                $where['_complex'] = $map;
                $where['pname'] = $uname;
                $where['m_type'] = ['in',array(1,3)];
                $where['g_type'] = '2';
                $where['i'] = '1';
                $where['result'] = ['EXP','IS NULL'];
                //查询当前用户所要评分考核信息表;
                $list = M('ping')->where($where)->distinct(true)->field('pid,uname,yue,target,norm,weight,value,rule,num,ment,result,standard,score,k_time,e_time')->order('uname desc')->select();
                // dump($list);
                // exit;
                $j_yue  = M('ping')->where(['pname'=>$uname,'m_type'=>['in',array(1,3)],'g_type'=>'2','i'=>'1','result'=> ['EXP','IS NULL']])->distinct(true)->field('k_time')->order('k_time desc')->select();
                if (empty($list)) {
                    $empty = '0';
                    $this->assign('empty',$empty);
                    $this->display();
                    exit;
                }
                // P($list);

                $time = date('Y');
                $empty = '1';
                $this->assign('time',$time);
                $this->assign('empty',$empty);
                $this->assign('list',$list);
                $this->assign('j_yue',$j_yue);
                $this->display();
            }
            


           // dump($j_yue);
           // exit;
            
        }
    }


    // public function wcailist()
    // {
    //     $this->display();
    // }

    //内部客户满意度
    public function nei()
    {
        
        //查询部门及用户考核信息;
        $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->find();
        $uname = $ulist['user'];
        $yue = date('m');
        $ri = date('d');
        
        if ($ri >= 10) {
            $dtime = date('Y-m').'-'.'11';
        }else{
            $dtime = date('Y-m').'-'.'10';
        }
        // echo $yue;
        // exit;
    

        $map['e_time'] = $dtime;
        $map['yue'] = $yue;
        $map['_logic'] = 'or';
        $where['_complex'] = $map;
        $where['pname'] = $uname;
        $where['m_type'] = 2;
        $where['result'] = ['EXP','IS NULL'];
        $plist = M('ping')->where($where)->distinct(true)->field('uname,yue,ment,result,pid,k_time,e_time')->select();
        // dump($plist);
        // exit;
        //  
        // P($plist);
        // $list = M('zong')->select();
        $time = date('Y');
        // $yue = date('m');
        $this->assign('list',$plist);
        $this->assign('time',$time);
        $this->assign('yue',$yue);
        $this->display();

    }

    //内部客户满意度评分操作
    public function xiang()
    {
        if (IS_POST) {
            // P(I());
            // $yue = date('m');
            // dump(I());
            // exit;
            $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->find();
            $uname = $ulist['user'];
            $num = ($_POST['gfen'] + $_POST['gofen'] + $_POST['ggfen'] + $_POST['zfen'] + $_POST['zzfen'])/5;
            // if ($_POST['zong'] != $num) {
            //     $this->error('总分错误,请填选平均分!');
            //     exit;
            // }
            $planarr = M('plan')->where(['id'=>$_POST['pid']])->find();
            $neipinglist['one'] = $_POST['gfen'];
            $neipinglist['tow'] = $_POST['gofen'];
            $neipinglist['three'] = $_POST['ggfen'];
            $neipinglist['four'] = $_POST['zfen'];
            $neipinglist['five'] = $_POST['zzfen'];
            $neipinglist['uname'] = $_POST['uname'];
            $neipinglist['pid'] = $_POST['pid'];
            $neipinglist['pname'] = $ulist['user'];
            $neipinglist['ment'] = $ulist['ment'];
            $neipinglist['k_time'] = $planarr['j_time'];
            $neipinglist['e_time'] = $planarr['e_time'];
            $neipinglist['yue'] = $planarr['yue'];
            $neipinglist['average'] = $num;
            $neipinglist['time'] = date('Y-m-d');
            // dump($neipinglist);
            // exit;

            // echo 'gao'.$gao;
            // echo 'zhong'.$zhong;
            // echo 'ji'.$ji;
            // exit;
            $where = [
                'uname' => $_POST['uname'],
                'pid' => $_POST['pid'],
                'pname' => $uname,
                // 'yue'  => $yue,
                'g_type'=>$_POST['g_type']
            ];
            $ping['result'] = $num;
            // // exit;
            // dump($where);
            // exit;
            // P($ping['result']);
            M('nei')->add($neipinglist);
            if (M('ping')->where($where)->save($ping) > 0) {
                $daytime = date('Y-m-d');
                $planlist = M('plan')->where(['id'=>$_POST['pid']])->find();
                $pinglist = M('ping')->where(['pid'=>$_POST['pid'],'uname'=>$_POST['uname'],'g_type'=>$_POST['g_type']])->distinct(true)->field('pname,e_time')->select();
                foreach ($pinglist as $key => $value) {
                        
                    $pingusers .= "`user`="."'".$value['pname']."'"." or ";
                   
                }
                $pingusers = rtrim($pingusers,'or ');
                // //評分總人數
                $pzong = M('ping')->where(['pid'=>$_POST['pid'],'uname'=>$_POST['uname'],'g_type'=>$_POST['g_type']])->distinct(true)->field('pname')->count();
                //已評人數
                $px = M('ping')->where(['pid'=>$_POST['pid'],'uname'=>$_POST['uname'],'result'=>['neq','null'],'g_type'=>$_POST['g_type']])->distinct(true)->field('pname')->select();
                $pnum =  count($px);
                if ($pnum == $pzong) {
                    //查询所有评分的分数
                    $pingnum = M('ping')->where(['pid'=>$_POST['pid'],'uname'=>$_POST['uname'],'g_type'=>$_POST['g_type']])->select();
                    
                    // dump($pingnum);
                    // exit;
                    $onearray = [];
                    foreach ($pingnum as $key => $value) {
                        $onearray[] = $value['result'];
                    }
                    //获取最高分和最低分
                    $pingmin = array_search(min($onearray),$onearray);
                    $pingmax = array_search(max($onearray),$onearray);
                    // echo $onearray[$pingmin];
                    // echo $onearray[$pingmax];
                    // exit;
                    $minlist = [];
                    //去除最低分
                    foreach ($pingnum as $key => $value) {
                        if ($value['result'] == $onearray[$pingmin]) {
                            // unset($value['result']);
                            // unset($value['pname']);
                            // unset($pingnum[$key]);
                            // $minlist[] = $value;
                            unset($pingnum[$key]);
                            // $pass[] = $value;
                            break;
                        }
                    }
                    // dump($pingnum);
                    // exit;
                    //去除最高分
                    foreach ($pingnum as $key => $value) {
                        if ($value['result'] == $onearray[$pingmax]) {
                            unset($pingnum[$key]);
                           
                           
                            break;
                        }
                    }
                    // dump($pingnum);
                    // exit;
                    //查询评分人
                    foreach ($pingnum as $key => $value) {
                        $pusers .= "`user`="."'".$value['pname']."'"." or ";
                    }
                    $pusers = rtrim($pusers,'or ');
                    // echo $pusers;
                    // exit;
                    $pnames = M('member')->where($pusers)->select();
                    // dump($pnames);
                    // exit;
                    $jnames = [];
                    $znames = [];
                    $gznames = [];
                    foreach ($pnames as $key => $value) {
                        if ($value['class'] == '2') {
                             $gnames[] = $value['user'];
                        }
                        if ($value['class'] == '1') {
                             $znames[] = $value['user'];
                        }
                        if ($value['class'] == '0') {
                             $jnames[] = $value['user'];
                        }
                    }

                    //得出高层评分
                    $gfen = [];
                    $zfen = [];
                    $jfen = [];
                    foreach ($pingnum as $key => &$value) {
                        if (in_array($value['pname'],$gnames)) {
                            // $value['result'] = $value['result']*0.5;
                            // $gsum = count($value);

                            $gfen[] = $value;
                            // $gfen['result'] = $gfen['result'] / $gsum;
                        }
                        if (in_array($value['pname'],$znames)) {
                            // $value['result'] = $value['result']*0.3;
                            $zfen[] = $value;
                        }
                        if (in_array($value['pname'],$jnames)) {
                            // $value['result'] = $value['result']*0.2;
                            $jfen[] = $value;
                        }
                    }
                    $gsum = count($gfen);
                    foreach ($gfen as $key => $value) {
                        $gresults[0]['result'] += $value['result'] / $gsum * 0.5;
                        // $gresults['result'] = $gresults['result']/$gsum;
                    }
                    $zsum = count($zfen);
                    foreach ($zfen as $key => $value) {
                        $zresults[0]['result'] += $value['result'] / $zsum * 0.3;
                        // $gresults['result'] = $gresults['result']/$gsum;
                    }
                    $jsum = count($jfen);
                    foreach ($jfen as $key => $value) {
                        $jresults[0]['result'] += $value['result'] / $jsum * 0.2;
                        // $gresults['result'] = $gresults['result']/$gsum;
                    }
                    // $gresult['result'] = $gresults['result'] / $gsum;
                    // foreach ($variable as $key => $value) {
                    //     # code...
                    // }
                    // dump($gresults);
                    // dump($zresults);
                    // dump($jresults);
                    // exit;
                    // // echo '<br>';
                    // // dump($zfen);
                    // // echo '<br>';
                    // // dump($jfen);
                    // exit;
                    // //将高层评分乘以基数
                    // foreach ($gfen as $key => &$value) {
                    //     $value['result'] = $value['result']*0.5;
                    // }
                    //总和所有评分人分数
                    $zongfen =  array_merge($gresults,$zresults,$jresults);
                    // dump($zongfen);
                    // exit;
                    foreach ($zongfen as $key => $value) {
                        $result += $value['result'];
                    }
                    // echo $result;
                    // exit;
                    // $usercount = count($zongfen);
                    // echo $usercount;
                    // exit;
                    // $result = $sumlist / $usercount;
                    if ($result > '85' && $result < '95') {
                       $cha = 95 - $result;
                       // echo $cha;
                       $que = $cha * 10;
                       $standard = 95 - $que;
                   
                    }else if($result >= '95'){
                                $standard = '100';
                    }else if($result <= '85'){
                                $standard = '0';
                    }
                    $weights = M('ping')->where(['pid'=>$_POST['pid']])->find();
                    $weight = $weights['weight'].'%';
                    $score = $standard / $weight;
                    $sping['result'] = $result;
                    $sping['standard'] = $standard;
                    $sping['score'] = $score;
                    M('people')->where(['uname'=>$_POST['uname'],'pid'=>$_POST['pid']])->save($sping);
                    // M('plan')->where(['id'=>$_POST['pid'],'yue'=>$yue])->save($sping);
                    // dump($sping);
                    // exit;
                    // echo $_POST['pid'];
               
                    // dump($gfen);
                    // echo '<br>';
                    // echo '-----------------------------------------------';
                    // dump($zfen);
                    // echo '<br>';
                    // echo '-----------------------------------------------';
                    // dump($jfen);
                    // exit;
                    // echo '1111';
                    // foreach ($px as $key => $value) {
                    //     $pxnames .= "`user`="."'".$value['pname']."'"." or ";
                    // }
                    // $pxnames = rtrim($pxnames,'or ');
                    // // echo $pxnames;
                    // // exit;
                    // $upusers = M('member')->where($pxnames)->select();
                    // $gusers = [];
                    // $zusers = [];
                    // $jusers = [];
                    // foreach ($upusers as $key => $value) {
                    //         if ($value['class'] == '2') {
                    //                 $gusers[] = $value;
                    //         }
                    //         if ($value['class'] == '1') {
                    //             $zusers[] = $value;
                    //         } 
                    //         if ($value['class'] == '0') {
                    //             $jusers[] = $value;
                    //         }
                    // }

                    // // dump($gusers);
                    // // dump($zusers);
                    // // dump($jusers);
                    // // exit;
                    // foreach ($gusers as $key => $value) {
                    //     $gnames .= "`pname`="."'".$value['user']."'"." or ";
                    //     // $gres .='('. "`pname`="."'".$value['user']."'"." or ".')'.'AND'.'('."`g_type`="."'".$_POST['g_type']."'".')';
                    // }
                    //  foreach ($zusers as $key => $value) {
                    //     $znames .= "`pname`="."'".$value['user']."'"." or ";
                    // }
                    //  foreach ($jusers as $key => $value) {
                    //     $jnames .= "`pname`="."'".$value['user']."'"." or ";
                    // }
                    // //高
                    // // $gnames = rtrim($gnames,'or ');
                    // $gres = '('. rtrim($gnames,'or ').')'.' AND '.'('."`pid` = "."'".$_POST['pid']."'".')';
                    // $glist = M('ping')->where($gres)->select();
                    // $gnum = M('ping')->where($gres)->count();
                    // foreach ($glist as $key => $value) {
                    //         $gzong += $value['result'];
                    // }
                    // //中
                    // $zres = '('. rtrim($znames,'or ').')'.' AND '.'('."`pid` = "."'".$_POST['pid']."'".')';
                    // $zlist = M('ping')->where($zres)->select();
                    // $znum = M('ping')->where($zres)->count();
                    // foreach ($zlist as $key => $value) {
                    //         $zzong += $value['result'];
                    // }
                    // //基
                    // $jres = '('. rtrim($jnames,'or ').')'.' AND '.'('."`pid` = "."'".$_POST['pid']."'".')';
                    // $jlist = M('ping')->where($jres)->select();
                    // $jnum = M('ping')->where($jres)->count();
                    // foreach ($jlist as $key => $value) {
                    //         $jzong += $value['result'];
                    // }
                    // $gstandard  = $gzong / $gnum;    //计算高层平均分
                    // $zstandard  = $zzong / $znum;     //计算中层平均分
                    // $jstandard  = $jzong / $jnum;      //计算基层平均分
                    // // echo $gzong.'---------'.$zzong.'----------'.$jzong;
                    // $sum = $gstandard + $zstandard + $jstandard;   //总和高中基总和
                    // echo $sum;
                    // exit;
                    // 计算计分规则  得出标准分
                   
                   
                   
                    
                 
                    // exit;
                }
                $this->success('評分成功!','nei');
            }else{
                $this->error('評分失敗!');
            }
          

        }else{
            // dump(I());
            // exit;
            
            $ulist = M('zong')->where(['uname'=>$_GET['uname'],'k_time'=>$_GET['k_time']])->select();
            // dump($_GET);
            // exit;
            $pid = $_GET['pid'];
            $yue = $_GET['k_time'];
            $g_type = $ulist[0]['g_type'];
            // P($list);
            $time = date('Y');
            $this->assign('time',$time);
            $this->assign('pid',$pid);
            $this->assign('yue',$yue);
            $this->assign('g_type',$g_type);
            $this->assign('ulist',$ulist);
            $this->display();
        }
    }



    //内部流程
    public function bu()
    {
        if (IS_POST) {
            // P(I());
            // $list = $_POST;
            // 查詢當前登入用戶信息
            $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->find();
            $uname = $ulist['user'];
            $list['result'] = $_POST['result'];
            $list['standard'] = $_POST['standard'];
            $list['score'] = $_POST['score'];
            if (empty($_POST['result'])) {
                echo '分数为空';
                exit;
            }
            // P($pzong);
            // dump($_POST);
            // dump($list);
            // exit;
            // P($res);
            if (M('ping')->where(['pid'=>$_POST['id'],'yue'=>$_POST['yue'],'pname'=>$uname,'uname'=>$_POST['uname']])->save($list) > 0) {
                    //評分總人數
                    $pzong = M('ping')->where(['pid'=>$_POST['id'],'uname'=>$_POST['uname']])->distinct(true)->field('pname')->count();
                    // echo $pzong;
                    // exit;
                    //已評人數
                    $px = M('ping')->where(['pid'=>$_POST['id'],'uname'=>$_POST['uname'],'result'=>['neq','null'],'standard'=>['neq','null'],'score'=>['neq','null']])->distinct(true)->field('pname')->count();
                    if ($px == $pzong) {
                        // echo '12';
                        // exit;
                        $zong = M('ping')->where(['pid'=>$_POST['id'],'uname'=>$_POST['uname'],'yue'=>$_POST['yue'],'result'=>['neq','null']])->distinct(true)->field('result,pname,standard,score')->select();
                        // P($result);
                        $rnum = 0;
                        $snum = 0;
                        $scnum = 0;
                        foreach ($zong as $key => $v) {
                            $rnum += $v['result'];
                            $snum += $v['standard'];
                            $scnum += $v['score'];
                           
                        }
                        // dump($zong);
                        // echo  $rnum . '/' .$snum. '/' . $scnum;
                        // exit;
                        //获得到诊完成率衡量结果核算结果的平均分;
                        $ping['result'] = $rnum / $pzong;
                        // //获得到诊完成率标准分的平均分;
                        $ping['standard'] = $snum / $pzong;
                        // //获得到诊完成率考核得分的平均分;
                        $ping['score'] = $scnum / $pzong;
                        // dump($ping);
                    
                        // echo $rnum;
                   
                        // exit;
                        M('people')->where(['pid'=>$_POST['id'],'uname'=>$_POST['uname'],'yue'=>$_POST['yue']])->save($ping);
                        M('plan')->where(['id'=>$_POST['id'],'yue'=>$_POST['yue']])->save($ping);

                    }
                    


                echo '1111';
            }else{
                echo '2222';
            }
        }else{
            //查询当前用户信息
            $uid = $_SESSION['uid'];
            $ulist = M('member')->where(['uid'=>$uid])->find();
            $yue = date('m');
            $ri = date('d');
            // echo $ri;
            // exit;
            if ($ri >= 10) {
                $dtime = date('Y-m').'-'.'11';
            }else{
                $dtime = date('Y-m').'-'.'10';
            }
                
            // P($ulist);
            $uname = $ulist['user'];
            // dump($ulist['ment']);
            // exit;
            if ($ulist['ment'] == '集团绩效管理委员会') {
               
                $type = '1'; 
            }else{
                $type = '2';
            }
            $map['e_time'] = $dtime;
            $map['yue'] = $yue;
            $map['_logic'] = 'or';
            $where['_complex'] = $map;
            $where['pname'] = $uname;
            $where['m_type'] = '3';
            // $where['g_type'] = '2';
            // $where['i'] = '1';
            $where['result'] = ['EXP','IS NULL'];
            //查询当前用户所要评分考核信息表;
            $list = M('ping')->where($where)->distinct(true)->field('pid,uname,yue,target,norm,weight,value,rule,num,ment,result,standard,score')->order('uname desc')->select();
                

            
            if (empty($list)) {
                $empty = '0';
                $this->assign('empty',$empty);
                $this->assign('type',$type);
                $this->display();
                exit;
            }
            // P($list);
            
            $time = date('Y');
            $empty = '1';
            $this->assign('type',$type);
            $this->assign('time',$time);
            $this->assign('empty',$empty);
            $this->assign('list',$list);
            $this->display();
        }
    }








    //学习成长
    public function xue()
    {
        if (IS_POST) {
            // P(I());
            // $list = $_POST;
            // 查詢當前登入用戶信息
            $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->find();
            $uname = $ulist['user'];
            $list['result'] = $_POST['result'];
            $list['standard'] = $_POST['standard'];
            $list['score'] = $_POST['score'];
            // dump($_POST);
            // exit;
            // P($pzong);
            
            // P($res);
            if (M('ping')->where(['pid'=>$_POST['id'],'yue'=>$_POST['yue'],'pname'=>$uname,'uname'=>$_POST['uname'],'m_type'=>'4'])->save($list) > 0) {
                    //評分總人數
                    $pzong = M('ping')->where(['pid'=>$_POST['id'],'uname'=>$_POST['uname']])->distinct(true)->field('pname')->count();
                    //已評人數
                    // echo $pzong;
                    // exit;
                    $px = M('ping')->where(['pid'=>$_POST['id'],'uname'=>$_POST['uname'],'result'=>['neq','null'],'standard'=>['neq','null'],'score'=>['neq','null']])->distinct(true)->field('pname')->count();
                    // echo $px;
                    // exit;
                    if ($px == $pzong) {
                        $zong = M('ping')->where(['pid'=>$_POST['id'],'uname'=>$_POST['uname'],'yue'=>$_POST['yue'],'result'=>['neq','null']])->distinct(true)->field('result,pname,standard,score')->select();
                        // P($result);
                        $rnum = 0;
                        $snum = 0;
                        $scnum = 0;
                        foreach ($zong as $key => $v) {
                            $rnum += $v['result'];
                            $snum += $v['standard'];
                            $scnum += $v['score'];
                           
                        }
                        // dump($zong);
                        // echo  $rnum . '/' .$snum. '/' . $scnum;
                        // exit;
                        //获得到诊完成率衡量结果核算结果的平均分;
                        $ping['result'] = $rnum / $pzong;
                        // //获得到诊完成率标准分的平均分;
                        $ping['standard'] = $snum / $pzong;
                        // //获得到诊完成率考核得分的平均分;
                        $ping['score'] = $scnum / $pzong;
                        // dump($ping);
                        // exit;
                        // echo $rnum;
                   
                        // exit;
                        M('people')->where(['pid'=>$_POST['id'],'uname'=>$_POST['uname']])->save($ping);
                        M('plan')->where(['id'=>$_POST['id']])->save($ping);
                    }
                    


                echo '1111';
            }else{
                echo '2222';
            }
        }else{
            //查询当前用户信息
            $uid = $_SESSION['uid'];
            $ulist = M('member')->where(['uid'=>$uid])->find();
            
            // P($ulist);
            $uname = $ulist['user'];
            $yue = date('m');
            $ri = date('d');
            // if ($ulist['ment'] == '集团绩效管理委员会') {
            //     //查询当前用户所要评分考核信息表;
            //     $list = M('ping')->where(['m_type'=>'4'])->distinct(true)->field('pid,uname,yue,target,norm,weight,value,rule,num,ment,result,standard,score')->order('uname desc')->select();
            // }else{
                $map['e_time'] = $dtime;
                $map['yue'] = $yue;
                $map['_logic'] = 'or';
                $where['_complex'] = $map;
                $where['pname'] = $uname;
                $where['m_type'] = '4';
                $where['result'] = ['EXP','IS NULL'];
                if ($ulist['ment'] == '集团绩效管理委员会') {
                    $ji = '1';
                    $ment = M('ping')->where($where)->distinct(true)->field('ment')->order('uname desc')->select();
                }
                //查询当前用户所要评分考核信息表;
                $list = M('ping')->where($where)->distinct(true)->field('pid,uname,k_time,target,norm,weight,value,rule,num,ment,result,standard,score,yue')->order('uname desc')->select();
                $j_yue = M('ping')->where($where)->distinct(true)->field('k_time')->order('uname desc')->select();
           
            if (empty($list)) {
                $empty = '0';
                $this->assign('ji',$ji);
                $this->assign('j_yue',$j_yue);
                $this->assign('ment',$ment);
                $this->assign('empty',$empty);
                $this->display();
                exit;
            }
            // P($list);
            // echo $ji;
            // exit;
            $time = date('Y');
            $empty = '1';
            $this->assign('ji',$ji);
            $this->assign('j_yue',$j_yue);
            $this->assign('ment',$ment);
            $this->assign('time',$time);
            $this->assign('empty',$empty);
            $this->assign('list',$list);
            $this->display();
        }
    }







    public function setnei()
    {
        if (IS_POST) {
            $list = $_POST;
            // $list['time'] = date('Y-m-s');
             // P($list);
          //   exit;
            //获取表格类型;
            $blist = M('people')->where(['id'=>$_POST['pid']])->select();

            // $bming = $blist['type'];
            //截取数组最后一个字段值
            $users = array_pop($list);
            // P($users);
            // exit;
            $res   = [];
            foreach ($users as $user) {
                    $arr = $list;
                    $arr['time'] = date('Y-m-d');
                    $arr['pname'] = $user;
                    $res[]        = $arr;

                
            }
            // $pname = [];
            foreach ($res as $key => $value) {
                    $pname[] = $value['pname'];
            }
            // dump($pname);
            $namet = array_unique($pname);
            // $iidt = array_unique($iid);
            $ipname['pname'] = implode(',',$namet);
            // dump($list);
            
            // exit;
            if (M('people')->where(['id'=>$list['pid']])->save($ipname) > 0) {
                    $plist = [];
                    foreach ($blist as $key => $v) {
                        foreach ($res as $key => $value) {
                                $tmp = $v;
                                $tmp['pname'] = $value['pname'];
                                unset($tmp['id']);
                                $plist[] = $tmp;
                        }
                    }
                    M()->startTrans();
                    foreach ($plist as $value) {
                        if (M('ping')->add($value) == 'false') {
                             M()->rollback();
                            return $this->error('添加失败');
                         }
                       
                    }
                    M()->commit();
                    echo '1111';
            }else{
                    echo '2222';
            }
            
            // dump($plist);
            // exit;
            // P($res);
            exit;
        }else{
            $me = M('member')->where(['uid'=>$_SESSION['uid']])->find();
            $yue = date('m');
            $ri = date('d');
            
            if ($ri >= 10) {
                $dtime = date('Y-m').'-'.'11';
            }else{
                $dtime = date('Y-m').'-'.'10';
            }
            $map['e_time'] = $dtime;
            $map['yue'] = $yue;
            $map['_logic'] = 'or';
            $where['_complex'] = $map;
            $where['pname'] = $uname;
            $where['xname'] = $me['user'];
            $where['pname'] = ['eq', ''];
            // $where['i'] = '1';
            $where['result'] = ['EXP','IS NULL'];
            $plist = M('people')->where($where)->select();
            // dump($plist);
            // exit;
            $ulist = M('member')->where(['user'=>['neq','admin']])->order('ment desc')->select();
            //------获取内部客户满意度过往的评分人
            $susers = M('member')->where(['uid'=>$_SESSION['uid']])->find();
            $pplist = M('people')->where(['xname'=>$susers['user']])->select();
            // dump($pplist);
            // exit;
            foreach ($pplist as $key => $value) {
                $nusers .= "`uname`="."'".$value['uname']."'"." or ";
            }

            $nusers = rtrim($nusers,'or ');

            $nusers = '('. rtrim($nusers,'or ').')'.' AND '.'('."`xname` = "."'".$susers['user']."'".')';
            // echo $nusers;
            // exit;
            $pusers = M('people')->where($nusers)->select();
            // dump($pusers);
            // exit;
            $pnames = [];
            foreach ($pusers as $key => $value) {
                if ($value['pname'] != NULL) {
                    $pnames[] = $value;
                }
            }
            $pnamearr = explode(",",$pnames[0]['pname']);
            //-----------得到评分人
            // dump($pnamearr);
            // exit;
            $res = [];  

            foreach ($ulist as $key => $value) {
              $res[$value['ment']][] = $value;
            }
            // dump($res);
            // exit;
            // if ($plist) {
            //     # code...
            // }
            $time = date('Y');
            $this->assign('list',$plist);
            $this->assign('pname',$pnamearr);
            $this->assign('ulist',$res);
            $this->assign('time',$time);
            $this->display();
        }
    }






    /**
     * [cha 网络中心财务指标选项查询]
     * @return [yue] [绩效月]
     * @return [type] [查看类型 0：未评分的表格； 1：已评分的表格]
     */
    public function cha()
    {
        $yue = date('m');
        // dump(I());
        // exit;
        if ($_POST['type'] == '0' && $_POST['yue'] == '0') {
                $uid = $_SESSION['uid'];
                $ulist = M('member')->where(['uid'=>$uid])->find();
                $uname = $ulist['user'];
                $ri = date('d');
                $yue = date('m');
    
                if ($ri >= 10) {
                    $dtime = date('Y-m').'-'.'11';
                }else{
                    $dtime = date('Y-m').'-'.'10';
                }

                $map['e_time'] = $dtime;
                $map['yue'] = $yue;
                $map['_logic'] = 'or';
                $where['_complex'] = $map;
                $where['pname'] = $uname;
                $where['m_type'] = ['in',array(1,3)];
                $where['g_type'] = '2';
                $where['i'] = '1';
                $where['result'] = ['EXP','IS  NULL'];
                //查询当前用户所要评分考核信息表;
                $list = M('ping')->where($where)->distinct(true)->field('pid,uname,yue,target,norm,weight,value,rule,num,ment,result,standard,score,k_time,e_time')->order('uname desc')->select();
                // dump($list);
                if (!empty($list)) {
                    $this->ajaxReturn($list);
                }else{
                    echo '2222';
                }
        }else{
            if ($_POST['type'] == '0') {
                $uid = $_SESSION['uid'];
                $ulist = M('member')->where(['uid'=>$uid])->find();
                $uname = $ulist['user'];

                //查询当前用户所要评分考核信息表;
                $list = M('ping')->where(['pname'=>$uname,'m_type'=>['in',array(1,3)],'g_type'=>'2','i'=>'1','k_time'=>$_POST['yue'],'result'=> ['EXP','IS NULL']])->distinct(true)->field('pid,uname,yue,target,norm,weight,value,rule,num,ment,result,standard,score,k_time,e_time')->order('uname desc')->select();
                // dump($list);
                if (!empty($list)) {
                    $this->ajaxReturn($list);
                }else{
                    echo '2222';
                }
                
            }else{
                if ($_POST['yue'] == '0') {
                    // echo '111';
                    // exit;
                    $uid = $_SESSION['uid'];
                    $ulist = M('member')->where(['uid'=>$uid])->find();
                    $uname = $ulist['user'];
                    
                    // dump($where);
                    // exit;
                   //查询当前用户所要评分考核信息表;
                    $list = M('ping')->where(['pname'=>$uname,'m_type'=>['in',array(1,3)],'g_type'=>'2','i'=>'1','result'=> ['EXP','IS NOT NULL']])->distinct(true)->field('pid,uname,yue,target,norm,weight,value,rule,num,ment,result,standard,score,k_time,e_time')->order('uname desc')->select();
                    // dump($list);
                    // exit;
                    foreach ($list as $key => $value) {
                        $value['zt'] = '1';
                        $arr[] = $value;
                    }
                    // dump($arr);
                    // exit;
                    if (!empty($arr)) {
                        $this->ajaxReturn($arr);
                    }else{
                        echo '2222';
                    }
                }else{
                    // echo '111';
                    // exit;
                    $uid = $_SESSION['uid'];
                    $ulist = M('member')->where(['uid'=>$uid])->find();
                    $uname = $ulist['user'];
                   //查询当前用户所要评分考核信息表;
                    $list = M('ping')->where(['pname'=>$uname,'m_type'=>['in',array(1,3)],'g_type'=>'2','i'=>'1','k_time'=>$_POST['yue'],'result'=> ['EXP','IS NOT NULL']])->distinct(true)->field('pid,uname,yue,target,norm,weight,value,rule,num,ment,result,standard,score,k_time,e_time')->order('uname desc')->select();
                    // dump($list);
                    // exit;
                     foreach ($list as $key => $value) {
                        $value['zt'] = '1';
                        $arr[] = $value;
                    }
                    if (!empty($arr)) {
                        $this->ajaxReturn($arr);
                    }else{
                        echo '2222';
                    }
                }
            }
        }
    }



    /**
     * [bulist 内部流程信息展示]
     * @return [type] [为：1展示公司全部]
     * @return [type] [为：2当前登入人已评分信息]
     */
    public function bulist()
    {
        $yue = date('m');
        $ri = date('d');
        $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->find();
        // echo $ri;
        // exit;
        // if ($ri >= 10) {
        //     $dtime = date('Y-m').'-'.'11';
        // }else{
            $dtime = date('Y-m').'-'.'10';
        // }
            
        // dump(I());
        switch ($_GET['type']) {
            case '1': //绩效组
                    $map['e_time'] = $dtime;
                    $map['yue'] = $yue;
                    $map['_logic'] = 'or';
                    $where['_complex'] = $map;
                    
                    $where['m_type'] = '3';
                    // $where['g_type'] = '2';
                    // $where['i'] = '1';
                    // $where['result'] = ['EXP','IS NULL'];
                    $list = M('ping')->where($where)->order('uname desc')->select();
                    $mentlist = M('ping')->where(['m_type'=>'3'])->distinct(true)->field('ment')->select();
                    $timelist = M('ping')->where(['m_type'=>'3'])->distinct(true)->field('k_time')->select();
                    $ji = '1';
                    $this->assign('ji',$ji);
                    $this->assign('list',$list);
                    $this->assign('mentlist',$mentlist);
                    $this->assign('timelist',$timelist);
                    $this->display();
                    // dump($list);
                    // exit;
                break;
            
            case '2': //对应查询人
                    // $map['e_time'] = $dtime;
                    // $map['yue'] = $yue;
                    // $map['_logic'] = 'or';
                    // $where['_complex'] = $map;
                    $where['pname'] = $ulist['user'];
                    $where['m_type'] = '3';
                    // $where['g_type'] = '2';
                    // $where['i'] = '1';
                    $where['result'] = ['EXP','IS NOT NULL'];
                    $list = M('ping')->where($where)->order('uname desc')->select();
                    $timelist = M('ping')->where($where)->distinct(true)->field('k_time')->select();
                    // dump($timelist);
                    // exit;
                    // $ji = '1';
                    // $this->assign('ji',$ji);
                    $this->assign('list',$list);
                    $this->assign('timelist',$timelist);
                    $this->display();
                break;
        }
    }


    /**
     * [xuelist 学习成长信息展示]
     */
    public function xuelist()
    {
        $yue = date('m');
        $ri = date('d');
        // echo $ri;
        // exit;
        if ($ri >= 10) {
            $dtime = date('Y-m').'-'.'11';
        }else{
            $dtime = date('Y-m').'-'.'10';
        }
        $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->find();
        if ($ulist['ment'] == '集团绩效管理委员会') {
            $map['e_time'] = $dtime;
            $map['yue'] = $yue;
            $map['_logic'] = 'or';
            $where['_complex'] = $map;
            $where['m_type'] = '4';
            $list = M('ping')->where($where)->order('uname desc')->select();
            $mentlist = M('ping')->where(['m_type'=>'4'])->distinct(true)->field('ment')->select();
            $timelist = M('ping')->where(['m_type'=>'4'])->distinct(true)->field('k_time')->select();
            $ji = '1';
            // dump($list);
            // exit;
            $this->assign('ji',$ji);
            $this->assign('list',$list);
            $this->assign('mentlist',$mentlist);
            $this->assign('timelist',$timelist);
            $this->display();
        }else{
            $map['e_time'] = $dtime;
            $map['yue'] = $yue;
            $map['_logic'] = 'or';
            $where['_complex'] = $map;
            $where['m_type'] = '4';
            $where['pname'] = $ulist['user'];
            $where['result'] = ['EXP','IS NOT NULL'];
            $list = M('ping')->where($where)->order('uname desc')->select();
            $mentlist = M('ping')->where(['m_type'=>'4','pname'=>$ulist['user'],'result'=>['EXP','IS NOT NULL']])->distinct(true)->field('ment')->select();
            $timelist = M('ping')->where(['m_type'=>'4','pname'=>$ulist['user'],'result'=>['EXP','IS NOT NULL']])->distinct(true)->field('k_time')->select();
            // $ji = '1';
            // $this->assign('ji',$ji);
            $this->assign('list',$list);
            $this->assign('mentlist',$mentlist);
            $this->assign('timelist',$timelist);
            $this->display();
        }

     
    }

    /**
     * [neilist 内部客户满意度信息展示]
     * @return [type] [description]
     */
    public function neilist()
    {
        $yue = date('m');
        $ri = date('d');
        // echo $ri;
        // exit;
        if ($ri >= 10) {
            $dtime = date('Y-m').'-'.'11';
        }else{
            $dtime = date('Y-m').'-'.'10';
        }
        $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->find();
        if ($ulist['ment'] == '集团绩效管理委员会') {
            $map['e_time'] = $dtime;
            $map['yue'] = $yue;
            $map['_logic'] = 'or';
            $where['_complex'] = $map;
            // $where['m_type'] = '2';
            $list = M('nei')->where($where)->order('uname desc')->select();
            $mentlist = M('nei')->distinct(true)->field('ment')->select();
            $timelist = M('nei')->distinct(true)->field('k_time')->select();
            $ji = '1';
            // dump($list);
            // exit;
            $this->assign('ji',$ji);
            $this->assign('list',$list);
            $this->assign('mentlist',$mentlist);
            $this->assign('timelist',$timelist);
            $this->display();
        }else{
            $map['e_time'] = $dtime;
            $map['yue'] = $yue;
            $map['_logic'] = 'or';
            $where['_complex'] = $map;
            // $where['m_type'] = '2';
            $where['pname'] = $ulist['user'];
            $where['one'] = ['EXP','IS NOT NULL'];
            $list = M('nei')->where($where)->order('uname desc')->select();
            $mentlist = M('nei')->where(['pname'=>$ulist['user'],'one'=>['EXP','IS NOT NULL']])->distinct(true)->field('ment')->select();
            $timelist = M('nei')->where(['pname'=>$ulist['user'],'one'=>['EXP','IS NOT NULL']])->distinct(true)->field('k_time')->select();
            // $ji = '1';
            // $this->assign('ji',$ji);
            $this->assign('list',$list);
            $this->assign('mentlist',$mentlist);
            $this->assign('timelist',$timelist);
            $this->display();
        }

    }


    /**
     * [xcha 下拉框查询]
     * @return [type] [0：；]
     */
    public function xcha()
    {
        // echo '111';
        // exit;
        $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->find();
        if ($ulist['ment'] == '集团绩效管理委员会') {
                switch ($_POST['type']) {
                    case '0':  //内部流程
                        if ($_POST['ment'] == '0' && $_POST['k_time'] == '0') {
                            $zonglist = M('ping')->order('uname desc')->select();
                            $this->ajaxReturn($zonglist);   
                        }else if($_POST['ment'] != '0' && $_POST['k_time'] == '0'){
                            $zonglist = M('ping')->where(['ment'=>$_POST['ment']])->order('ment desc')->select();
                              // dump($zonglist);
                              // exit;
                            $this->ajaxReturn($zonglist);
                        }else if($_POST['ment'] == '0' && $_POST['k_time'] != '0'){
                            $zonglist = M('ping')->where(['k_time'=>$_POST['k_time']])->order('ment desc')->select();
                            $this->ajaxReturn($zonglist);
                        }else if($_POST['ment'] != '0' && $_POST['k_time'] != '0'){
                            $zonglist = M('ping')->where(['k_time'=>$_POST['k_time'],'ment'=>$_POST['ment']])->order('ment desc')->select();
                            $this->ajaxReturn($zonglist);
                        }
                        break;
                    case '1': //内部流程
                        if ($_POST['ment'] == '0' && $_POST['k_time'] == '0') {
                            $zonglist = M('ping')->order('uname desc')->select();
                            $this->ajaxReturn($zonglist);   
                        }else if($_POST['ment'] != '0' && $_POST['k_time'] == '0'){
                            $zonglist = M('ping')->where(['ment'=>$_POST['ment']])->order('ment desc')->select();
                            $this->ajaxReturn($zonglist);
                        }else if($_POST['ment'] == '0' && $_POST['k_time'] != '0'){
                            $zonglist = M('ping')->where(['k_time'=>$_POST['k_time']])->order('ment desc')->select();
                            $this->ajaxReturn($zonglist);
                        }else if($_POST['ment'] != '0' && $_POST['k_time'] != '0'){
                            $zonglist = M('ping')->where(['k_time'=>$_POST['k_time'],'ment'=>$_POST['ment']])->order('ment desc')->select();
                            $this->ajaxReturn($zonglist);
                        }
                        break;
                    case '2': //职能中心财务指标
                        // dump($_POST);
                        // exit;
                        if ($_POST['table'] == '0' && $_POST['yue'] == '0') {
                            $zonglist = M('ping')->where(['m_type'=>['in',array(1,3)],'g_type'=>'1','i'=>'1'])->order('uname desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);   
                        }else if($_POST['table'] != '0' && $_POST['yue'] == '0'){
                            $zonglist = M('ping')->where(['m_type'=>['in',array(1,3)],'g_type'=>'1','i'=>'1','result'=>['EXP','IS NOT NULL']])->order('ment desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);   
                        }else if($_POST['table'] == '0' && $_POST['yue'] != '0'){
                            $zonglist = M('ping')->where(['m_type'=>['in',array(1,3)],'g_type'=>'1','i'=>'1','result'=>['EXP','IS NULL'],'k_time'=>$_POST['yue']])->order('ment desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);   
                        }else if($_POST['table'] != '0' && $_POST['yue'] != '0'){
                            $zonglist = M('ping')->where(['m_type'=>['in',array(1,3)],'g_type'=>'1','i'=>'1','result'=>['EXP','IS NOT NULL'],'k_time'=>$_POST['yue']])->order('ment desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);   
                        }
                        break;
                    case '3': //网络中心财务指标
                        // dump($_POST);
                        // exit;
                        if ($_POST['table'] == '0' && $_POST['yue'] == '0') {
                            $zonglist = M('ping')->where(['m_type'=>['in',array(1,3)],'g_type'=>'2','i'=>'1'])->order('uname desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);      
                        }else if($_POST['table'] != '0' && $_POST['yue'] == '0'){
                            $zonglist = M('ping')->where(['m_type'=>['in',array(1,3)],'g_type'=>'2','i'=>'1','result'=>['EXP','IS NOT NULL']])->order('ment desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);   
                        }else if($_POST['table'] == '0' && $_POST['yue'] != '0'){
                            $zonglist = M('ping')->where(['m_type'=>['in',array(1,3)],'g_type'=>'2','i'=>'1','result'=>['EXP','IS NULL'],'k_time'=>$_POST['yue']])->order('ment desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);   
                        }else if($_POST['table'] != '0' && $_POST['yue'] != '0'){
                            $zonglist = M('ping')->where(['m_type'=>['in',array(1,3)],'g_type'=>'2','i'=>'1','result'=>['EXP','IS NOT NULL'],'k_time'=>$_POST['yue']])->order('ment desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);   
                        }
                        break;
                    case '4': //学习成长
                        // dump($_POST);
                        // exit;
                        if ($_POST['ment'] == '0' && $_POST['k_time'] == '0') {
                            $zonglist = M('ping')->where(['m_type'=>'4'])->order('uname desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);      
                        }else if($_POST['ment'] != '0' && $_POST['k_time'] == '0'){
                            $zonglist = M('ping')->where(['m_type'=>'4','ment'=>$_POST['ment']])->order('ment desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);   
                        }else if($_POST['ment'] == '0' && $_POST['k_time'] != '0'){
                            $zonglist = M('ping')->where(['m_type'=>'4','k_time'=>$_POST['k_time']])->order('ment desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);   
                        }else if($_POST['ment'] != '0' && $_POST['k_time'] != '0'){
                            $zonglist = M('ping')->where(['m_type'=>'4','k_time'=>$_POST['k_time'],'ment'=>$_POST['ment']])->order('ment desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);   
                        }
                        break;
                    case '5': //学习成长
                        // dump($_POST);
                        // exit;
                        if ($_POST['ment'] == '0' && $_POST['k_time'] == '0') {
                            $zonglist = M('ping')->where(['m_type'=>'4'])->order('uname desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);      
                        }else if($_POST['ment'] != '0' && $_POST['k_time'] == '0'){
                            $zonglist = M('ping')->where(['m_type'=>'4','ment'=>$_POST['ment']])->order('ment desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);   
                        }else if($_POST['ment'] == '0' && $_POST['k_time'] != '0'){
                            $zonglist = M('ping')->where(['m_type'=>'4','k_time'=>$_POST['k_time']])->order('ment desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);   
                        }else if($_POST['ment'] != '0' && $_POST['k_time'] != '0'){
                            $zonglist = M('ping')->where(['m_type'=>'4','k_time'=>$_POST['k_time'],'ment'=>$_POST['ment']])->order('ment desc')->select();
                            $zlist = [];
                            foreach ($zonglist as $key => $value) {
                                    if (empty($value['result'])) {
                                        $value['zt'] = '未评分';
                                    }else{
                                        $value['zt'] = '已评分';
                                    }
                                    $zlist[] = $value;
                            }
                            $this->ajaxReturn($zlist);   
                        }
                        break;
                }
               
        }else{
            // dump(I());
            // exit;
            switch ($_POST['type']) {
                case '1':  //其他部门内部流程
                    $where['pname'] = $ulist['user'];
                    $where['m_type'] = '3';
                    $where['result'] = ['EXP','IS NOT NULL'];
                    if ($_POST['k_time'] == '0') {
                        $zonglist = M('ping')->where($where)->order('uname desc')->select();
                        $this->ajaxReturn($zonglist);   
                    }else if($_POST['k_time'] != '0'){
                        $zonglist = M('ping')->where(['pname'=>$ulist['user'],'k_time'=>$_POST['k_time'],'m_type'=>'3','result'=>['EXP','IS NOT NULL']])->order('ment desc')->select();
                        $this->ajaxReturn($zonglist);
                    }
                    break;
                case '5':  //其他部门内部流程
                    $where['pname'] = $ulist['user'];
                    $where['m_type'] = '4';
                    $where['result'] = ['EXP','IS NOT NULL'];
                    if ($_POST['k_time'] == '0') {
                        $zonglist = M('ping')->where($where)->order('uname desc')->select();
                        $zlist = [];
                        foreach ($zonglist as $key => $value) {
                                if (empty($value['result'])) {
                                    $value['zt'] = '未评分';
                                }else{
                                    $value['zt'] = '已评分';
                                }
                                $zlist[] = $value;
                        }
                        $this->ajaxReturn($zlist);      
                    }else if($_POST['k_time'] != '0'){
                        $zonglist = M('ping')->where(['pname'=>$ulist['user'],'k_time'=>$_POST['k_time'],'m_type'=>'4','result'=>['EXP','IS NOT NULL']])->order('ment desc')->select();

                        $zlist = [];
                        foreach ($zonglist as $key => $value) {
                                if (empty($value['result'])) {
                                    $value['zt'] = '未评分';
                                }else{
                                    $value['zt'] = '已评分';
                                }
                                $zlist[] = $value;
                        }
                        $this->ajaxReturn($zlist);   
                    }
                    break;
                
            }
            
        }   

        
    }



    /**
     * [sou 根据用户名搜索]
     * @return [user] [用户名]
     * @return [type] [类型 0：内部流程；1:学习成长]
     */
    public function sou()
    {
        $yue = date('m');
        $ri = date('d');
        // echo $ri;
        // exit;
        if ($ri >= 10) {
            $dtime = date('Y-m').'-'.'11';
        }else{
            $dtime = date('Y-m').'-'.'10';
        }
        $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->find();
        if ($ulist['ment'] != '集团绩效管理委员会') {
            $userlist = M('member')->where(['user'=>$_POST['user']])->find();
            if ($userlist['ment'] != $ulist['ment']) {
                echo '1111';
                exit;
            }else{
                $where['result'] = ['EXP','IS NOT NULL'];
            }
        }
        switch ($_POST['type']) {
          case '0':  //内部流程
                // dump(I());
                $map['e_time'] = $dtime;
                $map['yue'] = $yue;
                $map['_logic'] = 'or';
                $where['_complex'] = $map;
                $where['uname'] = array('like','%'.$_POST['user'].'%');
                $where['m_type'] = '3';
                $zonglist = M('ping')->where($where)->select();
                $this->ajaxReturn($zonglist);
            break;   //内部流程END
          
          case '1':  //学习成长
                // dump(I());
                // exit;
                // $map['e_time'] = $dtime;
                // $map['yue'] = $yue;
                // $map['_logic'] = 'or';
                // $where['_complex'] = $map;
                $where['uname'] = array('like','%'.$_POST['user'].'%');
                $where['m_type'] = '4';
                $zonglist = M('ping')->where($where)->select();
                $zlist = [];
                foreach ($zonglist as $key => $value) {
                        if (empty($value['result'])) {
                            $value['zt'] = '未评分';
                        }else{
                            $value['zt'] = '已评分';
                        }
                        $zlist[] = $value;
                }
                $this->ajaxReturn($zlist);   
            break;   //学习成长END
        }
    }





 }